<template>
	<view>
		<input class="uni-input" confirm-type="search" placeholder="搜索" v-model="text">
		<u-icon class="icon" name="search" color="#909399" :size="28" @click="search()"></u-icon></input>




		<view class="wrap">
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftlist" :key="index" @click="go(item)">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image[0]" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightlist" :key="index" @click="go(item)">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image[0]" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
					</view>
				</template>
			</u-waterfall>
		</view>







	</view>
</template>

<script>
	export default {
		data() {
			return {
				text: "",
				flowList: [],
				leftlist: [],
				rightlist: [],
			}
		},
		onLoad() {

		},
		methods: {
			async search() {
				this.leftlist=[],
				this.rightlist=[],
				console.log(this.vuex_token, "123")
				this.loadStatus = 'loading';
				const {
					data: res
				} = await this.$http(`/queryCommodity?name=${this.text}`, "get", this.vuex_token)
				console.log(res.data)
				res.data.forEach(item => {
					console.log(item)
					item.image = item.image.split(',')
				})
				for (let i = 0; i < res.data.length; i++) {
					if (i % 2 != 0) {
						this.rightlist.push(res.data[i])
					} else {
						this.leftlist.push(res.data[i])
					}
				}

				// this.list=res.data
				this.loadStatus = 'loadmore';
			},
			go(id) {
				console.log(id)
				uni.navigateTo({
					url: `../submitBar/index?title=${id.title}&image=${id.image}&desc=${id.desc}&price=${id.price}&type_id=${id.type_id}&id=${id.id}`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.divder {
		margin-top: 100rpx;
	}

	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.icon {
		position: absolute;
		right: 10rpx;
		top: 16rpx;
	}

	.uni-input {
		padding: 18rpx 30rpx;
		background-color: rgb(234, 234, 234);
		border-radius: 100rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 16rpx;
		font-size: 26rpx;
		color: $u-tips-color;
		margin-left: 10rpx;
	}
</style>
